import lejos.nxt.Button;
import lejos.nxt.ButtonListener;

public class WaitController implements ButtonListener {
	private AudioAlert audioAlert;
	private MowController mowController;

	private boolean obstacleFound = false;

	Button enter = Button.ENTER;
	Button left = Button.LEFT;
	Button esc = Button.ESCAPE;

	public WaitController(AudioAlert audioAlert,
			MowController mowController) {
		this.audioAlert = audioAlert;
		this.mowController = mowController;

		enter.addButtonListener(this);
		left.addButtonListener(this);
		esc.addButtonListener(this);
	}

	public void obstacleFound() {
		mowController.pause();
		audioAlert.enableSound();
		obstacleFound = true;
	}

	public void obstacleCleared() {
		obstacleFound = false;
	}

	public void buttonPressed(Button b) {
		if (b == esc) {
			mowController.pause();
		} else if (!obstacleFound && b == enter) {
			mowController.resume();
			audioAlert.disableSound();
		} else if (b == left) {
			mowController.stop();
			audioAlert.disableSound();
		}
	}

	public void buttonReleased(Button b) {
	}
}
